home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBGRX100.ARJ / BITDRAW.H < prev    next >
Text File  |  1992-04-10  |  12KB  |  368 lines

  1. /** 
  2.  ** BITDRAW.H 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifndef _BITDRAW_H_
  25. #define _BITDRAW_H_
  26.  
  27. #ifdef  __TURBOC__
  28. #pragma inline
  29. #endif
  30.  
  31. /*
  32.  * utilities -- other files may define them too
  33.  */
  34. #ifndef _SaveDS
  35.  
  36. #ifdef  __TURBOC__
  37. #define _ClrDir()    asm cld
  38. #define _SetDir()    asm std
  39. #define _SaveDS()    asm push ds
  40. #define _RestoreDS()    asm pop  ds
  41. #endif
  42.  
  43. #ifdef  __GNUC__
  44. #define _ASV        asm volatile
  45. #define _ClrDir()    _ASV("cld")
  46. #define _SetDir()    _ASV("std")
  47. #define _SaveDS()
  48. #define _RestoreDS()
  49. #endif
  50.  
  51. #endif  /* _SaveDS */
  52.  
  53. /*
  54.  * instruction fragment to set up the VGA for subsequent
  55.  * bit mask register writes
  56.  */
  57. #ifdef  __TURBOC__
  58. #define __EGAINIT__                                \
  59.     asm mov        dx,VGA_GR_CTRL_PORT;                    \
  60.     asm mov        al,VGA_BIT_MASK_REG;                    \
  61.     asm out        dx,al;                            \
  62.     asm inc        dx
  63. #endif
  64. #ifdef  __GNUC__
  65. #define __EGAINIT__                             "\n\
  66.     movl    $L_VGA_GR_CTRL_PORT,%%edx                  \n\
  67.     movb    $L_VGA_BIT_MASK_REG,%%al                  \n\
  68.     outb    %%al,%%dx                          \n\
  69.     incl    %%edx                                "
  70. #endif
  71.  
  72. /*
  73.  * mask and data output instruction fragments for line and font drawing
  74.  *   mask in al, data address in es:[di] (edi)
  75.  *   (ANDBYTE1: can destroy mask)
  76.  *   (ANDBYTE2: can use ah for temporary)
  77.  */
  78. #ifdef  __TURBOC__
  79. #define __INVMASK__        asm not        al
  80. #define __EGAMASK__        asm out        dx,al
  81. #define __EGABYTE__        asm inc        BYTE PTR es:[di]
  82. #define __XORBYTE__        asm xor        BYTE PTR es:[di],al
  83. #define __ORBYTE__        asm or        BYTE PTR es:[di],al
  84. #define __ANDBYTE1__                                \
  85.     asm not        al;                                \
  86.     asm and        BYTE PTR es:[di],al
  87. #define __ANDBYTE2__                                \
  88.     asm mov        ah,al;                            \
  89.     asm not        ah;                                \
  90.     asm and        BYTE PTR es:[di],ah
  91. #endif
  92. #ifdef  __GNUC__
  93. #define __INVMASK__        "notb   %%al"
  94. #define __EGAMASK__        "outb   %%al,%%dx"
  95. #define __EGABYTE__        "incb   (%%edi)"
  96. #define __XORBYTE__        "xorb   %%al,(%%edi)"
  97. #define __ORBYTE__        "orb    %%al,(%%edi)"
  98. #define __ANDBYTE1__                             "\n\
  99.     notb    %%al                              \n\
  100.     andb    %%al,(%%edi)                            "
  101. #define __ANDBYTE2__                             "\n\
  102.     movb    %%al,%%ah                          \n\
  103.     notb    %%ah                              \n\
  104.     andb    %%ah,(%%edi)                            "
  105. #endif
  106.  
  107. /*
  108.  * line drawing, X major
  109.  *   putmask: how to output the mask
  110.  *   putbyte: how to output the current byte
  111.  *   init:    what to do before starting
  112.  */
  113. #ifdef  __TURBOC__
  114. #define __XLINE__(addr,offs,deltx,delty,mask,putbyte,putmask,init) do {        \
  115.     init;                                    \
  116.     asm les        di,DWORD PTR addr;                        \
  117.     asm mov        si,WORD  PTR delty;                        \
  118.     asm mov        ax,WORD  PTR mask;                        \
  119.     asm mov        cx,WORD  PTR deltx;                        \
  120.     asm mov        bx,cx;                            \
  121.     asm shr        bx,1;                            \
  122.     asm inc        cx;                                \
  123.       Xline##putbyte##Loop:                            \
  124.     putmask;                                \
  125.     putbyte;                                \
  126.     asm ror        al,1;                            \
  127.     asm adc        di,0;                            \
  128.     asm sub        bx,si;                            \
  129.     asm jnc        Xline##putbyte##NoAdjust;                    \
  130.     asm add        bx,deltx;                            \
  131.     asm add        di,offs;                            \
  132.       Xline##putbyte##NoAdjust:                            \
  133.     asm loop    Xline##putbyte##Loop;                    \
  134. } while(0)
  135. #endif
  136. #ifdef  __GNUC__
  137. #define __XLINE__(adr,ofs,deltx,delty,msk,putbyte,putmask,init) _ASV(     "\n\
  138.     "init"                                  \n\
  139.     movl    %0,%%edi                          \n\
  140.     movl    %3,%%esi                          \n\
  141.     movl    %4,%%eax                          \n\
  142.     movl    %2,%%ecx                          \n\
  143.     movl    %%ecx,%%ebx                          \n\
  144.     shrl    $1,%%ebx                          \n\
  145.     incl    %%ecx                              \n\
  146. L_Xline"#putbyte"Loop:                              \n\
  147.     "putmask"                              \n\
  148.     "putbyte"                              \n\
  149.     rorb    $1,%%al                              \n\
  150.     adcl    $0,%%edi                          \n\
  151.     subl    %%esi,%%ebx                          \n\
  152.     jnc    L_Xline"#putbyte"NoAdjust                  \n\
  153.     addl    %2,%%ebx                          \n\
  154.     addl    %1,%%edi                          \n\
  155. L_Xline"#putbyte"NoAdjust:                          \n\
  156.     loop    L_Xline"#putbyte"Loop                       "\
  157.     : /* NOTHING */                                \
  158.     : "g" (adr), "g" (ofs), "g" (deltx), "g" (delty), "g" (msk)        \
  159.     : "di", "si", "dx", "cx", "bx", "ax"                    \
  160. )
  161. #endif
  162.  
  163. /*
  164.  * line drawing, Y major
  165.  *   putmask: how to output the mask
  166.  *   putbyte: how to output the current byte
  167.  *   init:    what to do before starting
  168.  */
  169. #ifdef  __TURBOC__
  170. #define __YLINE__(addr,offs,deltx,delty,mask,putbyte,putmask,init) do {        \
  171.     init;                                    \
  172.     asm mov        al,BYTE  PTR mask;                        \
  173.     asm les        di,DWORD PTR addr;                        \
  174.     asm mov        si,WORD  PTR offs;                        \
  175.     asm mov        cx,WORD  PTR delty;                        \
  176.     asm mov        bx,cx;                            \
  177.     asm shr        bx,1;                            \
  178.     asm inc        cx;                                \
  179.     putmask;                                \
  180.       Yline##putbyte##Loop:                            \
  181.     putbyte;                                \
  182.     asm sub        bx,deltx;                            \
  183.     asm jnc        Yline##putbyte##NoAdjust;                    \
  184.     asm add        bx,delty;                            \
  185.     asm ror        al,1;                            \
  186.     asm adc        di,0;                            \
  187.     putmask;                                \
  188.       Yline##putbyte##NoAdjust:                            \
  189.     asm add        di,si;                            \
  190.     asm loop    Yline##putbyte##Loop;                    \
  191. } while(0)
  192. #endif
  193. #ifdef  __GNUC__
  194. #define __YLINE__(adr,ofs,deltx,delty,msk,putbyte,putmask,init) _ASV(     "\n\
  195.     "init"                                  \n\
  196.     movl    %0,%%edi                          \n\
  197.     movl    %1,%%esi                          \n\
  198.     movl    %4,%%eax                          \n\
  199.     movl    %3,%%ecx                          \n\
  200.     movl    %%ecx,%%ebx                          \n\
  201.     shrl    $1,%%ebx                          \n\
  202.     incl    %%ecx                              \n\
  203.     "putmask"                              \n\
  204. L_Yline"#putbyte"Loop:                              \n\
  205.     "putbyte"                              \n\
  206.     subl    %2,%%ebx                          \n\
  207.     jnc    L_Yline"#putbyte"NoAdjust                  \n\
  208.     addl    %3,%%ebx                          \n\
  209.     rorb    $1,%%al                              \n\
  210.     adcl    $0,%%edi                          \n\
  211.     "putmask"                              \n\
  212. L_Yline"#putbyte"NoAdjust:                          \n\
  213.     addl    %%esi,%%edi                          \n\
  214.     loop    L_Yline"#putbyte"Loop                       "\
  215.     : /* NOTHING */                                \
  216.     : "g" (adr), "g" (ofs), "g" (deltx), "g" (delty), "g" (msk)        \
  217.     : "di", "si", "dx", "cx", "bx", "ax"                    \
  218. )
  219. #endif
  220.  
  221. #define _DrawLineEGA(AD,OF,X,Y,MS) do {                        \
  222.     if(X > Y) __XLINE__(AD,OF,X,Y,MS,__EGABYTE__,__EGAMASK__,__EGAINIT__);  \
  223.     else      __YLINE__(AD,OF,X,Y,MS,__EGABYTE__,__EGAMASK__,__EGAINIT__);  \
  224. } while(0)
  225.  
  226. #define _DrawLineXor(AD,OF,X,Y,MS) do {                        \
  227.     if(X > Y) __XLINE__(AD,OF,X,Y,MS,__XORBYTE__,,);                \
  228.     else      __YLINE__(AD,OF,X,Y,MS,__XORBYTE__,,);                \
  229. } while(0)
  230.  
  231. #define _DrawLineOr(AD,OF,X,Y,MS) do {                        \
  232.     if(X > Y) __XLINE__(AD,OF,X,Y,MS,__ORBYTE__,,);                \
  233.     else      __YLINE__(AD,OF,X,Y,MS,__ORBYTE__,,);                \
  234. } while(0)
  235.  
  236. #define _DrawLineAnd(AD,OF,X,Y,MS) do {                        \
  237.     if(X > Y) __XLINE__(AD,OF,X,Y,MS,__ANDBYTE2__,,);                \
  238.     else      __YLINE__(AD,OF,X,Y,MS,__ANDBYTE2__,,);                \
  239. } while(0)
  240.  
  241. /*
  242.  * font drawing
  243.  */
  244. #ifdef  __TURBOC__
  245. #define __FNTROW__(adr,bits,wdt,shft,mask,putbyte,putmask,init,inv) do {    \
  246.     init;                                    \
  247.     asm les        di,DWORD PTR adr;                        \
  248.     asm lds        si,DWORD PTR bits;                        \
  249.     asm mov        cx,WORD  PTR shft;                        \
  250.     asm jcxz    FontNS##putbyte##inv##Init;                    \
  251.     asm mov        bx,WORD  PTR wdt;                        \
  252.     asm or        bx,bx;                            \
  253.     asm jz        FontSFT##putbyte##inv##TestMask;                \
  254. FontSFT##putbyte##inv##Loop:                            \
  255.     asm lodsb;                                \
  256.     inv;                                    \
  257.     asm xor        ah,ah;                            \
  258.     asm ror        ax,cl;                            \
  259.     asm or        al,ch;                            \
  260.     asm mov        ch,ah;                            \
  261.     putmask;                                \
  262.     putbyte;                                \
  263.     asm inc        di;                                \
  264.     asm dec        bx;                                \
  265.     asm jnz        FontSFT##putbyte##inv##Loop;                \
  266. FontSFT##putbyte##inv##TestMask:                        \
  267.     asm or        bx,WORD  PTR mask;                        \
  268.     asm jz        Font##putbyte##inv##End;                    \
  269.     asm lodsb;                                \
  270.     inv;                                    \
  271.     asm shr        al,cl;                            \
  272.     asm or        al,ch;                            \
  273.     asm and        al,bl;                            \
  274.     asm jmp        Font##putbyte##inv##LastByte;                \
  275. FontNS##putbyte##inv##Init:                            \
  276.     asm mov        cx,WORD  PTR wdt;                        \
  277.     asm jcxz    FontNS##putbyte##inv##TestMask;                \
  278. FontNS##putbyte##inv##Loop:                            \
  279.     asm lodsb;                                \
  280.     inv;                                    \
  281.     putmask;                                \
  282.     putbyte;                                \
  283.     asm inc        di;                                \
  284.     asm loop    FontNS##putbyte##inv##Loop;                    \
  285. FontNS##putbyte##inv##TestMask:                            \
  286.     asm or        cx,WORD  PTR mask;                        \
  287.     asm jz        Font##putbyte##inv##End;                    \
  288.     asm lodsb;                                \
  289.     inv;                                    \
  290.     asm and        al,cl;                            \
  291. Font##putbyte##inv##LastByte:                            \
  292.     putmask;                                \
  293.     putbyte;                                \
  294. Font##putbyte##inv##End: ;                            \
  295. } while(0)
  296. #endif
  297. #ifdef  __GNUC__
  298. #define __FNTROW__(adr,bits,wdt,shft,mask,putbyte,putmask,init,inv) _ASV("\n\
  299.     "init"                                  \n\
  300.     movl    %0,%%edi                          \n\
  301.     movl    %1,%%esi                          \n\
  302.     movl    %3,%%ecx                          \n\
  303.     jecxz    L_FontNS"#putbyte #inv"Init                  \n\
  304.     movl    %2,%%ebx                          \n\
  305.     orl    %%ebx,%%ebx                          \n\
  306.     jz    L_FontSFT"#putbyte #inv"TestMask              \n\
  307. L_FontSFT"#putbyte #inv"Loop:                          \n\
  308.     lodsb                                  \n\
  309.     "inv"                                  \n\
  310.     xorb    %%ah,%%ah                          \n\
  311.     rorw    %%cl,%%ax                          \n\
  312.     orb    %%ch,%%al                          \n\
  313.     movb    %%ah,%%ch                          \n\
  314.     "putmask"                              \n\
  315.     "putbyte"                              \n\
  316.     incl    %%edi                              \n\
  317.     decl    %%ebx                              \n\
  318.     jnz    L_FontSFT"#putbyte #inv"Loop                  \n\
  319. L_FontSFT"#putbyte #inv"TestMask:                      \n\
  320.     orl    %4,%%ebx                          \n\
  321.     jz    L_Font"#putbyte #inv"End                  \n\
  322.     lodsb                                  \n\
  323.     "inv"                                  \n\
  324.     shrb    %%cl,%%al                          \n\
  325.     orb    %%ch,%%al                          \n\
  326.     andb    %%bl,%%al                          \n\
  327.     jmp    L_Font"#putbyte #inv"LastByte                  \n\
  328. L_FontNS"#putbyte #inv"Init:                          \n\
  329.     movl    %2,%%ecx                          \n\
  330.     jcxz    L_FontNS"#putbyte #inv"TestMask                  \n\
  331. L_FontNS"#putbyte #inv"Loop:                          \n\
  332.     lodsb                                  \n\
  333.     "inv"                                  \n\
  334.     "putmask"                              \n\
  335.     "putbyte"                              \n\
  336.     incl    %%edi                              \n\
  337.     loop    L_FontNS"#putbyte #inv"Loop                  \n\
  338. L_FontNS"#putbyte #inv"TestMask:                      \n\
  339.     orl    %4,%%ecx                          \n\
  340.     jz    L_Font"#putbyte #inv"End                  \n\
  341.     lodsb                                  \n\
  342.     "inv"                                  \n\
  343.     andb    %%cl,%%al                          \n\
  344. L_Font"#putbyte #inv"LastByte:                          \n\
  345.     "putmask"                              \n\
  346.     "putbyte"                              \n\
  347. L_Font"#putbyte #inv"End:                           "\
  348.     : /* NOTHING */                                \
  349.     : "g" (adr), "g" (bits), "g" (wdt), "g" (shft), "g" (mask)        \
  350.     : "di", "si", "dx", "cx", "bx", "ax"                    \
  351. )
  352. #endif
  353.  
  354. #define _CharFGRowEGA(A,B,W,S,M) \
  355.     __FNTROW__(A,B,W,S,M,__EGABYTE__,__EGAMASK__,__EGAINIT__,)
  356. #define _CharFGRowXor(A,B,W,S,M) __FNTROW__(A,B,W,S,M,__XORBYTE__,,,)
  357. #define _CharFGRowOr(A,B,W,S,M)  __FNTROW__(A,B,W,S,M,__ORBYTE__,,,)
  358. #define _CharFGRowAnd(A,B,W,S,M) __FNTROW__(A,B,W,S,M,__ANDBYTE1__,,,)
  359.  
  360. #define _CharBGRowEGA(A,B,W,S,M) \
  361.     __FNTROW__(A,B,W,S,M,__EGABYTE__,__EGAMASK__,__EGAINIT__,__INVMASK__)
  362. #define _CharBGRowXor(A,B,W,S,M) __FNTROW__(A,B,W,S,M,__XORBYTE__,,,__INVMASK__)
  363. #define _CharBGRowOr(A,B,W,S,M)  __FNTROW__(A,B,W,S,M,__ORBYTE__,,,__INVMASK__)
  364. #define _CharBGRowAnd(A,B,W,S,M) __FNTROW__(A,B,W,S,M,__ANDBYTE1__,,,__INVMASK__)
  365.  
  366. #endif  /* whole file */
  367.  
  368.